package core.controller
{
	import core.Main;
	import core.view.VUSprite;
	
	import flash.events.Event;
	
	import org.ais.system.Ais;
	import org.aisy.interfaces.IClear;

	public class SkinLayoutManager implements IClear
	{
		static protected var instance:SkinLayoutManager
		
		public function SkinLayoutManager()
		{
			init();
		}
		
		protected function init():void
		{
			__addEvent();
		}
		
		protected function __addEvent():void
		{
			Ais.IMain.stage.addEventListener(Event.RESIZE, __stageResizeHandler);
		}
		
		protected function __removeEvent():void
		{
			Ais.IMain.stage.removeEventListener(Event.RESIZE, __stageResizeHandler);
		}
		
		protected function __stageResizeHandler(e:Event):void
		{
			var _w:Number = Ais.IMain.stage.stageWidth;
			var _h:Number = Ais.IMain.stage.stageHeight;
			
//			with (Main.IS.graphics) {
//				clear();
//				beginFill(0x111111);
//				drawRect(0, 0, _w, _h);
//				endFill();
//			}
			
			var i:uint = Main.IS.numChildren;
			var obj:*;
			while (i > 0) {
				i--;
				obj = Main.IS.getChildAt(i);
				if (obj is VUSprite) obj.setSize(_w, _h);
			}
		}
		
		public function clear():void
		{
			__removeEvent();
			instance = null;
		}
		
		static public function getInstance():SkinLayoutManager
		{
			if (null === instance) instance = new SkinLayoutManager();
			return instance;
		}
		
	}
}